<%@ page language="java" contentType="text/html; charset=UTF-8"
    import="ecs.dogear.app.*,java.util.*"
    pageEncoding="UTF-8"%>
<%
    int userId = Integer.parseInt(request.getParameter("id"));
	ArrayList<Comment> comments = CommenterDatabase.getCommentsOf(userId);
    StringBuilder sb = new StringBuilder("[");
    if(comments.size() > 0){
        for(int i = 0;i < comments.size();i++){
            Comment comment = comments.get(i);
            if(i != 0)
                sb.append(",");
            sb.append("{title:'");
            sb.append(StringUtil.escape(comment.getPageTitle()));
            sb.append("',url:'");
            sb.append(comment.getUrl());
            sb.append("',comment:'");
            sb.append(StringUtil.escape(comment.getContent()));
            sb.append("',replies:[");
            for(int j = 0;j < comment.getReplies().size();j++){
                if(j != 0)sb.append(",");
                sb.append("{reply:'");
                sb.append(comment.getReplies().get(j).getContent());
                sb.append("'}");
            }
            sb.append("]}");
        }        
    }
    sb.append("]");
    out.println(sb.toString());
%>